<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>图书管理系统</title>
    <meta name="description" content="图书管理">
    <meta name="keywords" content="图书管理">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
        .el-main {
            position: absolute;
            top: 70px;
            bottom: 0px;
            left: 200px;
            right: 10px;
            padding: 0;
        }
    </style>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <el-container>
        <el-header class="main-header" style="height:70px;">
            <nav class="navbar navbar-static-top" :class=''>
                <!-- Logo -->
                <a href="#" class="logo" style="text-align:center">
                    <span class="logo-lg"><img src="../img/logo.png" width="50px" height="35px"></span>
                </a>
                <a class="logo" style="text-align:center;">
                    <span style="margin: 40px 0 0 0;color: black">图书管理系统</span>
                </a>
                <div class="right-menu">
                    <el-dropdown class="avatar-container right-menu-item" trigger="click">
                        <div class="avatar-wrapper">
                            <img src="../img/user6-128x128.jpg" class="user-avatar">
                            <span v-html="user_name"></span>
                        </div>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item divided>
                                <el-button @click="handleUpdate()" type="text">修改密码</el-button>
                            </el-dropdown-item>
                            <el-dropdown-item divided>
                                <a href="../login.html">退出登录</a>
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </nav>
        </el-header>
        <el-container>
            <el-aside width="240px">
                <el-menu>
                    <el-menu-item v-for="menu in menuList" :index="menu.path">
                        <el-menu-item :index="menu.path">
                            <a :href="menu.linkUrl" style="display: inline-block;width: 180px"
                               target="right">{{menu.title}}</a>
                        </el-menu-item>
                    </el-menu-item>
                </el-menu>
            </el-aside>
            <el-container>
                <iframe name="right" class="el-main" src="Home.html" width="100%" height="580px"
                        frameborder="0"></iframe>
            </el-container>
        </el-container>
    </el-container>

    <el-dialog title="修改用户个人信息" :visible.sync="dialogFormVisible4Edit">
        <el-form ref="dataEditForm" :model="formData" label-position="right" label-width="100px">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="用户名称" prop="user_name">
                        <el-input disabled="disabled" v-model="formData.user_name"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="用户密码" prop="user_password">
                        <el-input v-model="formData.user_password"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="用户邮箱" prop="user_email">
                        <el-input v-model="formData.user_email"/>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
            <el-button type="primary" @click="handleEdit()">确定</el-button>
        </div>
    </el-dialog>

</div>


</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            user_name: window.location.href.split("=")[1],
            dialogFormVisible4Edit: false,
            formData: {},//表单数据
            menuList: [
                {
                    "path": "1",
                    "title": "首页",
                    "linkUrl": "Home.html"
                },
                {
                    "path": "2",
                    "title": "图书借阅",
                    "linkUrl": "Userbook.html"
                },
                {
                    "path": "3",
                    "title": "借阅历史",
                    "linkUrl": "Userreturn.html"
                },
                {
                    "path": "4",
                    "title": "图书管理",
                    "linkUrl": "Adminbook.html"
                },
                {
                    "path": "5",
                    "title": "读者管理",
                    "linkUrl": "Adminuser.html"
                },
                {
                    "path": "6",
                    "title": "图书归还",
                    "linkUrl": "Adminborrow.html"
                },
                {
                    "path": "7",
                    "title": "图书归还信息",
                    "linkUrl": "Adminreturn.html"
                },
            ]
        },
        methods: {
            findName() {
                user_name = window.location.href.split("=")[1];
            },
            handleUpdate() {
                this.dialogFormVisible4Edit=true;
                username=window.location.href.split("=")[1]
                //回显数据
                axios.get("/admin/findByName.do?name="+username).then((res)=>{
                    if(res.data.flag){
                        this.formData=res.data.data;
                    }else {
                        //查询失败
                        this.$message.error(res.data.message);
                    }
                });
            },
            handleEdit() {
                this.$refs['dataEditForm'].validate((valid)=>{
                    if (valid){
                        //表单校验通过，可以提交数据
                        axios.post("/admin/edituser.do",this.formData).then((res)=>{
                            if (res.data.flag){
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                })
                            }else {
                                this.$message.error(res.data.message)
                            }
                        }).finally(()=>{
                            //隐藏编辑窗口
                            this.dialogFormVisible4Edit = false;
                        });
                    }else {
                        //表单校验不通过
                        this.$message.error("表单数据校验失败");
                        return false;
                    }
                })
            },
        }
    });
    $(function () {
        var wd = 200;
        $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
